Page({

  data: {

  },

  onLoad: function (e) {
    let ordernum = e.ordernum;
    var ytimesf = e.ytimes.split(":")[0]
    var ytimesm = e.ytimes.split(":")[1]
    this.setData({
      ordernum,
      rightNum: e.greenNum,
      errNum: e.redNum,
      unAnswerNum: e.allQuestionCount - e.redNum - e.greenNum,
      ytimesf: ytimesf,
      ytimesm: ytimesm,
    })
    this.onQuery(e.examid);
  },
  onQuery: function(exam) {
    let that = this;

    const db = wx.cloud.database()
    db.collection('exams').doc(exam).get().then(res => {
      console.log('[数据库] [查询记录] 成功: ', res)
      let exam = res.data;
      let unit = exam.total/exam.num;
      that.setData({
        exam: exam,
        unit: unit
      });
    })
  },
  onReady: function () {

  },

  onShow: function () {

  },

  examBack: function () {
    wx.redirectTo({
      url: "../exam/exam?timeback=1&passf=" + this.data._repeat_passf + "&time=" + (this.data._repeat_time - 1) + "&training_qids=0&nums=" + this.data._repeat_num
    });
  },
  goReview: function () {
    let url = '/pages/review/review?ordernum='+this.data.ordernum;
    wx.navigateTo({
      url: url
    })
  },
  exam_repeat: function () {
    let url = '/pages/index/index';
    wx.reLaunch({
      url: url
    })
  },

  _repeat_examGo: function (e) {
    if (!e.data.category.time) return wx.showLoading({
      title: "考题读取中"
    }), void setTimeout(function () {
      wx.hideLoading();
    }, 999);
    wx.removeStorage({
      key: "exam" + this.data.category.id
    }), wx.removeStorage({
      key: "examlist" + this.data.category.id
    }), wx.removeStorage({
      key: "examind" + this.data.category.id
    }), wx.removeStorage({
      key: "examids" + this.data.category.id
    }), wx.removeStorage({
      key: "examall" + this.data.category.id
    }), wx.redirectTo({
      url: "../exam/exam?passf=" + e.data.category.passf + "&time=" + (e.data.category.time - 1) + "&training_qids=0&nums=" + e.data.category.number
    });
  }
})